package team.com;

import org.anddev.andengine.entity.modifier.MoveModifier;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.anddev.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.anddev.andengine.entity.sprite.Sprite;

import android.view.MenuItem;
import team.com.SceneManager.SceneType;

public class MainMenuScene extends BaseScene implements IOnMenuItemClickListener
{
	private final int MENU_PLAY = 0;
	private final int MENU_OPTIONS = 1;
	private Sprite menuBackground;
	private MenuScene menuChildScene;
	
	private void createBackground()
	{//
		menuBackground = new Sprite(0, 0, RSManager.menu_backgound_region);
		this.attachChild(menuBackground);
		
	}
	
	private void createMenuChildScene()
	{
		menuChildScene = new MenuScene(camera);
		menuChildScene.setPosition(0,0);
		
		final IMenuItem playMenuItem = new ScaleMenuItemDecorator(
				new SpriteMenuItem(MENU_PLAY, RSManager.play_region), 1.2f, 1);
		
		final IMenuItem optionsMenuItem = new ScaleMenuItemDecorator(
				new SpriteMenuItem(MENU_OPTIONS, RSManager.options_region), 1.2f, 1); 
		
		menuChildScene.addMenuItem(playMenuItem);
		menuChildScene.addMenuItem(optionsMenuItem);
		
		playMenuItem.registerEntityModifier(new MoveModifier(2.0f, 120, 120, 110, 110));
		optionsMenuItem.registerEntityModifier(new MoveModifier(2.0f, 260, 260, 110, 110));
		 
		menuChildScene.buildAnimations();
		menuChildScene.setBackgroundEnabled(false); 
		 
		menuChildScene.setOnMenuItemClickListener(this);
		this.setChildScene(menuChildScene);
		
		    
	}
	//private MenuItem _subMenu; 
	
	
	
	@Override
	public void createScene() {
		createBackground();
		createMenuChildScene();
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onBackKeyPressed() {
		// TODO Auto-generated method stub
		
		System.exit(0);
	}

	@Override
	public SceneType getSceneType() {
		// TODO Auto-generated method stub
		return SceneType.SCENE_MENU;
	}

	@Override
	public void disposeScene() {
		// TODO Auto-generated method stub
		menuBackground.detachSelf();
		menuChildScene.detachSelf();
		this.detachSelf();
		this.disposeScene();
	}

	@Override
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
			float pMenuItemLocalX, float pMenuItemLocalY) {
		 switch(pMenuItem.getID())
	        {
	        case MENU_PLAY:
	        	SceneManager.getInstance().loadGameScene();
	            return true;
	        case MENU_OPTIONS:
	            return true;
	        default:
	        	return false;
	        }
	}


}
